//
//  YINavigationBar.m
//  一点互助
//
//  Created by rimi on 16/8/19.
//  Copyright © 2016年 shen. All rights reserved.
//

#import "YINavigationBar.h"


@implementation YINavigationBar


+(UIBarButtonItem *)navBarItem:(NSString *)imageName title:(NSString *)title who:(id)who click:(SEL)click items:(NSInteger)items{
       //文字按钮
       UIBarButtonItem *navTextItem = [[UIBarButtonItem alloc]initWithTitle:title style:UIBarButtonItemStylePlain target:who action:click];
       //有图片的按钮
       UIBarButtonItem *navImageItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:who action:click];
       //items为2则返回有图片的
       if (items == 2) {
              return navImageItem;
       }else{
       return navTextItem;
       }
}
//文字加图片按钮
+(UIButton *)setItem:(id)who click:(SEL)click{
       UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
       //设置图片
       UIImage *imageForButton = [UIImage imageNamed:@"down"];
       // imageEdgeInsets 为'上左下右', 正值远离中心, 负值向中心聚拢. 具体以单词'inset'来记忆 */
       [button setTitleEdgeInsets:UIEdgeInsetsMake(0, -imageForButton.size.width - 10, 0, imageForButton.size.width)];
       [button setImageEdgeInsets:UIEdgeInsetsMake(0, button.titleLabel.bounds.size.width+30, 0, -button.titleLabel.bounds.size.width)];
       [button setImage:imageForButton forState:UIControlStateNormal];
       //设置文字
       NSString *buttonTitleStr = @"成都";
       [button setTitle:buttonTitleStr forState:UIControlStateNormal];
       button.titleLabel.font = [UIFont systemFontOfSize:17];
       [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
       button.frame = CGRectMake(0, 0 , kScreenWidthScale* 50, kScreenHeightScale* 30);
       [button addTarget:who action:click forControlEvents:UIControlEventTouchUpInside];
       return button;
}

//搜索框有点击事件
+(UITextField *)setTitleView:(NSString *)text who:(id)who click:(SEL)click{
       UITextField *search = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 250, 30)];
       UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidthScale * 40,kScreenHeightScale * 30)];
       view.backgroundColor = [UIColor clearColor];
       [search addSubview:view];
       
       [search setBackground:[UIImage imageNamed:@"搜索框"]];
       search.placeholder = text;
       
       search.font = [UIFont systemFontOfSize:14];
       UIImageView *leftImage=[[UIImageView alloc]initWithFrame:CGRectMake(10, 5, kScreenWidthScale*20, kScreenHeightScale *20)];
       leftImage.image=[UIImage imageNamed:@"放大镜"];
       [view addSubview:leftImage];
       search.leftView = view;
       search.leftViewMode=UITextFieldViewModeAlways; //此处用来设置leftview现实时机
       
       UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
       button.frame = search.frame;
       button.backgroundColor = [UIColor clearColor];
       [search addSubview:button];
       [button addTarget:who action:click forControlEvents:UIControlEventTouchUpInside];
       return search;
}

@end
